#ifndef COMPUTESERVER_HH
#define COMPUTESERVER_HH

#include "../library/thread.hh"
#include "../library/mutex.hh"
#include "../library/socket.hh"

#include "clientinstance.hh"
#include "clientcounter.hh"

#include <list>
#include <iostream>
#include <string>

using namespace std;
using namespace NM;

class ComputeServer : Thread, Mutex
{
private: // variables
    bool                    _run;                       // Mutex protected / used to stop main thread
    Socket                  _network;

private: // main thread variables
    list<ClientInstance*>   _clients;                   // List of clients using the server
    clientCounter           _counter;                   // Client counter class to share with client instancies

public: // interface
    ComputeServer();
    ComputeServer(string address, int port);
    void Start();
    void Stop();

    void loop();                                        // Thread execution

private: // internals
    bool init();
    bool isRunning();
    void setRunning(bool run);
};

void *compute_server_starter(void *data);

#endif // COMPUTESERVER_HH
